package com.icreate.storm.methods.indicators;

import com.icreate.entity.indicator.IndicatorID;
import com.icreate.entity.indicator.X2field;
import com.icreate.storm.methods.common.DateMethod;
import org.apache.storm.tuple.Values;

/**
 * Created by yc on 2017/5/12.
 */
public class X2Indicator extends BaseIndicator {
    public static final String typeName = "x2xdr";

    @Override
    public String getTypeName() {
        return typeName;
    }

    public static final String[] fields = {"type", "cellid", "imsi", "imei", "IndicatorID",
            "x2xdr.switch_request", "x2xdr.switch_success"
    };
    public static final String[] baseFields = {
            "x2xdr.switch_request", "x2xdr.switch_success"
    };

    @Override
    public String[] getBaseFields() {
        return baseFields;
    }

    public String[] getFields() {
        return fields;
    }

    public Values getValues(Object s) {
        X2field field = (X2field) s;

//        if (cells.length < 13)
//            return null;
//        if (ts.equals("") || cellid.equals("") || imsi.equals(""))
//            return null;


        long status = getValue(field.getStatus());
        long procudureType = getValue(field.getProcedureType());
        if (procudureType != 1L || field.getStatus().equals(""))
            return null;

        Values values = new Values("x2xdr", field.getCellid(), field.getImsi(), field.getImei(), field);
        values.add(1L);
        if (status == 0)
            values.add(1L);
        else
            values.add(0L);
        return values;
    }

    private long getRequest(long type, long procedureType) {
        if (procedureType == type)
            return 1;
        else
            return 0;
    }

    private long getSuccess(long type, long procedureType, long status) {
        if (procedureType == type && status == 0)
            return 1;
        else
            return 0;
    }
}

